#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import JTK.jmaya.core as jmc

except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class RubbishNode(CheckBase):
    def __init__(self):
        super(RubbishNode, self).__init__()
        pass

    def check(self):
        result_proc = jmc.list_rubbish_node()
        if result_proc:
            result_log = u'Error:%s\n' % result_proc
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        result_proc = jmc.list_rubbish_node()
        if result_proc:
            try:
                for i in result_proc:
                    if cmds.lockNode(i, q=1, l=1) == [True]:
                        cmds.lockNode(i, l=0)
                    cmds.delete(i)
                result_log = u'Succeed:%s已经删除\n' % result_proc
                return result_log
            except:
                return u'Error:%s没有删除成功\n' % result_proc
